﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataAccess.Product;
using FOModels.Product;
using System.Data;
using System.Net;
namespace Bussiness.Product
{
    public class ProductBLL
    {
        private ProductDAL dal;
        public ProductBLL()
        {
            dal = new ProductDAL();
        }
        public ProductModels getProductByID(int ProductID, int langid)
        {

            ProductModels fur = new ProductModels();
            DataTable tb = dal.getProductbyID(ProductID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {

                    fur.ProductID = int.Parse(row[0].ToString());
                    fur.ProductCID = int.Parse(row[1].ToString());
                    fur.ProductName = row[6].ToString();
                    fur.Publish = bool.Parse(row[2].ToString());
                    fur.ProductIcon = row[3].ToString();
                    fur.Description = WebUtility.HtmlDecode(row[7].ToString());
                }
                return fur;
            }
            else
            {
                return null;
            }

        }
        public List<ProductModels> getProductBy(int langid)
        {

            List<ProductModels> list = new List<ProductModels>();
            ProductModels fur;
            DataTable tb = dal.getProductby(langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new ProductModels();
                    fur.ProductID = int.Parse(row["ProductID"].ToString());
                    fur.ProductName = row["ProductName"].ToString();
                    list.Add(fur);

                }

            }
            return list;
        }
        public List<ProductCategoryModels> gettop3catebynews(int langid)
        {

            List<ProductCategoryModels> list = new List<ProductCategoryModels>();
            ProductCategoryModels fur;
            DataTable tb = dal.gettop3catebynews(langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new ProductCategoryModels();
                    fur.ProductCID = int.Parse(row["ProductCID"].ToString());
                    fur.Name = row["Name"].ToString();
                    list.Add(fur);

                }

            }
            return list;
        }
        
        public List<ProductCategoryModels> getProductCate(int langid)
        {

            List<ProductCategoryModels> list = new List<ProductCategoryModels>();
            ProductCategoryModels fur;
            DataTable tb = dal.getProductCate(langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new ProductCategoryModels();
                    fur.ProductCID = int.Parse(row["ProductCID"].ToString());
                    fur.Name = row["Name"].ToString();
                    list.Add(fur);

                }

            }
            return list;
        }

        public int UpdateProductDesriptionLang(ProductModels models, int langid)
        {
            if (dal.UpdateProductDesriptionLang(models, langid) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }



    }
}
